/*
 * ﻿Copyright (C) 2013 NewMain Softech
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package com.newmainsoftech.eatestutil.container;

import javax.ejb.embeddable.EJBContainer;
import javax.naming.Context;
import javax.naming.NamingException;

import org.junit.AfterClass;

/**
 * EJB test helper class of what sub-class may become test suite class for EJB bean class testing.<br />
 * 
 * @author Arata Y.
 */
public class EjbTestManagerBase {
	// static member signatures -------------------------------------------------------------------
	private static EjbContainerMate ejbContainerMate;
		public static EjbContainerMate getEjbContainerMate() {
			return ejbContainerMate;
		}
		public static void setEjbContainerMate( final EjbContainerMate ejbContainerMate) {
			EjbTestManagerBase.ejbContainerMate = ejbContainerMate;
		}

	public static <T> T lookupBy( final Class<T> type) throws NamingException {
		return getEjbContainerMate().contextLookup( type);
	}
	
	public static <T> T lookupBy( final Class<?> implClass, final Class<T> interfaceClass) 
	throws NamingException {
		return getEjbContainerMate().contextLookup( implClass, interfaceClass);
	}
	
	@AfterClass
	public static void staticTearDown() throws Exception {
		final Context context = getEjbContainerMate().getContext();
			if ( context != null)  context.close();
		final EJBContainer ejbContainer = getEjbContainerMate().getEjbContainer();
			if ( ejbContainer != null) ejbContainer.close();
	}
	// --------------------------------------------------------------------------------------------
}
